//
//  WLCloudController.m
//  WanLian
//
//  Created by xz on 2018/9/6.
//  Copyright © 2018年 wanlian. All rights reserved.
//

#import "WLCloudController.h"
//#import "YXJRAToolView.h"
#import "WLPhotoCloudController.h"
#import "JXCategoryView.h"
#import "WLVideoVController.h"
//#import "WLAudioVController.h"
#import "WLDownUploaVController.h"
#import <AssetsLibrary/AssetsLibrary.h>
#import "WLFileUpDownLoadModel.h"
#import "WLFileHandle.h"
#import "WLUpLoadCenter.h"
#import "WLDownLoadCenter.h"
#import "WLFileHandle.h"
#import "HXPhotoManager.h"
#import "HXDatePhotoToolManager.h"
#import "HXDatePhotoViewController.h"
#import "HXCustomNavigationController.h"


@interface WLCloudController ()<UIScrollViewDelegate,JXCategoryViewDelegate,HXDatePhotoViewControllerDelegate,UINavigationControllerDelegate>

//@property (nonatomic, assign) float photoSize;
@property (nonatomic, strong) WLPhotoCloudController *photoVC;
@property (nonatomic, strong) WLVideoVController *videoVC;
@property (nonatomic, strong) UIImageView *redPointView;

@property (strong, nonatomic) HXPhotoManager *photoManager;
@property (nonatomic, strong) HXPhotoManager *videoManager;
@property (strong, nonatomic) HXDatePhotoToolManager *toolManager;
//@property (nonatomic, strong) WLPhotoCloudController *audioVC;

@end

@implementation WLCloudController


- (HXDatePhotoToolManager *)toolManager {
    if (!_toolManager) {
        _toolManager = [[HXDatePhotoToolManager alloc] init];
    }
    return _toolManager;
}

- (HXPhotoManager *)photoManager {
    if (!_photoManager) {
        _photoManager = [[HXPhotoManager alloc] initWithType:HXPhotoManagerSelectedTypePhoto];
        _photoManager.configuration.openCamera = YES;
        _photoManager.configuration.reserveCameraList = YES;
        _photoManager.configuration.photoMaxNum = 9;
        _photoManager.configuration.saveSystemAblum = YES;
        _photoManager.configuration.photoCanEdit = NO;
        _photoManager.configuration.videoCanEdit = NO;
        _photoManager.configuration.filtrationICloudAsset = YES;
        _photoManager.configuration.showDateSectionHeader = NO;
        _photoManager.configuration.selectTogether = NO;
        _photoManager.configuration.saveToSystemAblumBeforeOut = YES;
        _photoManager.configuration.notNeedCacheHistory = YES;
        _photoManager.configuration.requestImageAfterFinishingSelection = NO;
        _photoManager.configuration.albumShowMode = HXPhotoAlbumShowModePopup;
    }
    return _photoManager;
}
- (HXPhotoManager *)videoManager {
    if (!_videoManager) {
        _videoManager = [[HXPhotoManager alloc] initWithType:HXPhotoManagerSelectedTypeVideo];
        _videoManager.configuration.openCamera = YES;
        _videoManager.configuration.reserveCameraList = YES;
        _videoManager.configuration.videoMaxNum = 9;
        _videoManager.configuration.videoMaximumDuration = 60 * 60 * 2;
        _videoManager.configuration.videoMaxDuration = 60 * 60 * 3;
        _videoManager.configuration.filtrationICloudAsset = YES;
        _videoManager.configuration.saveSystemAblum = YES;
        _videoManager.configuration.showDateSectionHeader = NO;
        _videoManager.configuration.selectTogether = NO;
        _videoManager.configuration.filtrationICloudAsset = YES;
        _videoManager.configuration.saveToSystemAblumBeforeOut = YES;
        _videoManager.configuration.notNeedCacheHistory = YES;
        _videoManager.configuration.requestImageAfterFinishingSelection = YES;
        _videoManager.configuration.albumShowMode = HXPhotoAlbumShowModePopup;
    }
    return _videoManager;
}
- (void)dealloc {
    [[NSNotificationCenter defaultCenter]removeObserver:self name:kUpDownloadTaskCompleteNofication object:nil];
}
- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.title = @"云盘";
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(judgeHaveTask) name:kUpDownloadTaskCompleteNofication object:nil];
    UIButton *btnUpDown = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 50, 44)];
    [btnUpDown setImage:[UIImage imageNamed:@"cloud_updown"] forState:UIControlStateNormal];
    [btnUpDown addTarget:self action:@selector(upDownloadAction) forControlEvents:UIControlEventTouchUpInside];
    UIBarButtonItem *rightBar = [[UIBarButtonItem alloc]initWithCustomView:btnUpDown];
    self.navigationItem.rightBarButtonItem = rightBar;
    
    UIButton *btnLogin = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, WIDTH_SCREEN_WL, WLScaleX(49))];
//    btnLogin.bounds = CGRectMake(0, 0, WIDTH_SCREEN_WL, WLScaleX(49));
    CAGradientLayer *gradientBtn = [CAGradientLayer layer];
    gradientBtn.frame = btnLogin.bounds;  // 设置显示的frame
    gradientBtn.colors = @[(__bridge id)wlUIColorRGB(0x1A59E2).CGColor,(__bridge id)wlUIColorRGB(0x2292F5).CGColor]; // 设置渐变颜色
    gradientBtn.startPoint = CGPointMake(0, 0);
    gradientBtn.endPoint = CGPointMake(1, 0);
    [btnLogin.layer insertSublayer:gradientBtn atIndex:0];
    
    btnLogin.titleLabel.font = [WLCommonTool fontTypePingFangSCMedium:16];
    [btnLogin setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [btnLogin setTitle:@"上传" forState:UIControlStateNormal];
    [btnLogin addTarget:self action:@selector(uploadAction) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:btnLogin];

    WLWkSelf
    [btnLogin mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.equalTo(weakSelf.view.mas_bottom).offset(-WL_Bottom);
        make.left.right.equalTo(weakSelf.view);
        make.height.equalTo(@(WLScaleX(49)));
    }];
    
//    NSArray *titleNameArr = @[@"照片",@"视频",@"音乐"];
    NSArray *titleNameArr = @[@"照片",@"视频"];
    
    CGFloat height = HEIGHT_SCREEN_WL-WL_NavTopHeight-WLScaleX(40)-WLScaleX(49)-WL_Bottom;
    UIScrollView *scrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, WLScaleX(40), WIDTH_SCREEN_WL, height)];
    scrollView.delegate = self;
    scrollView.pagingEnabled = YES;
    scrollView.contentSize = CGSizeMake(WIDTH_SCREEN_WL*(titleNameArr.count), height);
    scrollView.bounces = NO;
    scrollView.showsHorizontalScrollIndicator = NO;
    scrollView.showsVerticalScrollIndicator = NO;
    [self.view addSubview:scrollView];
    
    JXCategoryTitleView *categoryView = [[JXCategoryTitleView alloc] initWithFrame:CGRectMake(0, 0, WIDTH_SCREEN_WL, WLScaleX(40))];
    categoryView.backgroundColor = [UIColor whiteColor];
    categoryView.delegate = self;
    categoryView.titles = titleNameArr;
    categoryView.titleColor = wlLightTextColor;
    categoryView.titleSelectedColor = wlBlackColor;
    categoryView.cellWidth = WLScaleX(50);
    categoryView.titleFont = [WLCommonTool fontTypePingFangSCRegular:16];
    //2、添加并配置指示器
    //lineView
    JXCategoryIndicatorLineView *lineView = [[JXCategoryIndicatorLineView alloc] init];
    lineView.indicatorLineViewColor = wlblueColor;
    lineView.indicatorLineWidth = WLScaleX(75);//JXCategoryViewAutomaticDimension;
    lineView.lineStyle = JXCategoryIndicatorLineStyle_IQIYI;
    //backgroundView
    //    JXCategoryIndicatorBackgroundView *backgroundView = [[JXCategoryIndicatorBackgroundView alloc] init];
    //    backgroundView.backgroundViewColor = [UIColor redColor];
    //    backgroundView.backgroundViewWidth = JXCategoryViewAutomaticDimension;
    categoryView.indicators = @[lineView];
    
    //3、绑定contentScrollView。self.scrollView的初始化细节参考源码。
    categoryView.contentScrollView = scrollView;
    [self.view addSubview:categoryView];
    
    _photoVC = [WLPhotoCloudController new];
    _videoVC = [WLVideoVController new];
//    _audioVC = [WLAudioVController new];
    NSArray *controllerArray = @[_photoVC,_videoVC];
    
    for (int i = 0;  i<titleNameArr.count; i++) {
        UIViewController *controller = controllerArray[i];
        controller.view.frame = CGRectMake(WIDTH_SCREEN_WL*i, 0, WIDTH_SCREEN_WL, height);
        [self addChildViewController:controller];
        [scrollView addSubview:controller.view];
    }
    categoryView.defaultSelectedIndex = _index;
//    scrollView.contentOffset = CGPointMake(WIDTH_SCREEN_WL*2, 0);
////    [categoryView selectItemAtIndex:1];
    /*
    YXJRAToolView *myView = [[YXJRAToolView alloc]initWithSelected:0 withTitleArray:titleNameArr];
//    myView.titleView.backgroundColor = HPWhiteColor;
    [self.view addSubview:myView];
    [myView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.equalTo(self.view);
    }];
    
    WLPhotoCloudController *investbegVC = [WLPhotoCloudController new];//已付款
//    investbegVC.enterType = 0;
    WLPhotoCloudController *investingVC = [WLPhotoCloudController new];//计息中
//    investingVC.enterType = 1;
    WLPhotoCloudController *endInestVC = [WLPhotoCloudController new];//已回款
    //    YXJRANoInvestmentController *noInvestVC = [YXJRANoInvestmentController new];
    NSArray *controllerArray = @[investbegVC,investingVC,endInestVC];
    
    for (int i = 0;  i<titleNameArr.count; i++) {
        UIViewController *controller = controllerArray[i];
        controller.view.frame = CGRectMake(WIDTH_SCREEN_WL*i, 0, WIDTH_SCREEN_WL, HEIGHT_SCREEN_WL);
        [self addChildViewController:controller];
        [myView.bottomScroll addSubview:controller.view];
    }
    */
}

- (void)uploadAction
{
    /**
    if (_index==0) {
        UIAlertController *alertController = [UIAlertController alertControllerWithTitle:nil message:nil preferredStyle:UIAlertControllerStyleActionSheet];

        UIAlertAction *photo = [UIAlertAction actionWithTitle:@"我的相册" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
            [self chooseHeadimgAction:UIImagePickerControllerSourceTypePhotoLibrary];
        }];
        //                [photo setValue:wlblueColor forKey:@"_titleTextColor"];
        [alertController addAction:photo];

        UIAlertAction *camera = [UIAlertAction actionWithTitle:@"拍照" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
            [self chooseHeadimgAction:UIImagePickerControllerSourceTypeCamera];
        }];
        //                [camera setValue:wlblueColor forKey:@"_titleTextColor"];
        [alertController addAction:camera];

        UIAlertAction *cancel = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
        }];
        //                [cancel setValue:wlblueColor forKey:@"_titleTextColor"];
        [alertController addAction:cancel];

        [self presentViewController:alertController animated:YES completion:nil];
    }
    else if (_index==1)
    {
        [self chooseMovieAction];
    }*/
    
    
    if (_index==0) {
        HXDatePhotoViewController *vc = [[HXDatePhotoViewController alloc] init];
        vc.manager = self.photoManager;
        vc.delegate = self;
        HXCustomNavigationController *nav = [[HXCustomNavigationController alloc] initWithRootViewController:vc];
        nav.supportRotation = self.photoManager.configuration.supportRotation;
        [self presentViewController:nav animated:YES completion:nil];
    }
    else if (_index==1)
    {
        HXDatePhotoViewController *vc = [[HXDatePhotoViewController alloc] init];
        vc.manager = self.videoManager;
        vc.delegate = self;
        HXCustomNavigationController *nav = [[HXCustomNavigationController alloc] initWithRootViewController:vc];
        nav.supportRotation = self.videoManager.configuration.supportRotation;
        [self presentViewController:nav animated:YES completion:nil];
    }
}
- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    [self judgeHaveTask];
}
#pragma mark - HXDatePhotoViewControllerDelegate
- (void)datePhotoViewController:(HXDatePhotoViewController *)datePhotoViewController didDoneAllList:(NSArray<HXPhotoModel *> *)allList photos:(NSArray<HXPhotoModel *> *)photoList videos:(NSArray<HXPhotoModel *> *)videoList original:(BOOL)original {
    if (photoList.count > 0) {
        [self addTaskWithListArr:photoList fileType:SPFileTypePhoto];
    } else if (videoList.count > 0) {
        [self addTaskWithListArr:videoList fileType:SPFileTypeVideo];
    }
}

- (void)upDownloadAction
{
    WLDownUploaVController *uploadDownController = [[WLDownUploaVController alloc] init];
    [self.navigationController pushViewController:uploadDownController animated:YES];
}

#pragma mark - JXCategoryViewDelegate
- (void)categoryView:(JXCategoryBaseView *)categoryView didSelectedItemAtIndex:(NSInteger)index {
    //侧滑手势处理
    //    if (_shouldHandleScreenEdgeGesture) {
    //        self.navigationController.interactivePopGestureRecognizer.enabled = (index == 0);
    //    }
    _index = index;
    WLLog(@"____%ld",(long)index);
}

- (void)chooseHeadimgAction:(UIImagePickerControllerSourceType)type
{
    UIImagePickerController *imagePickerController = [[UIImagePickerController alloc] init];
    imagePickerController.delegate = self;
    imagePickerController.sourceType = type;
    imagePickerController.mediaTypes = @[(__bridge NSString *)kUTTypeImage];
//    imagePickerController.allowsEditing = YES;
    imagePickerController.navigationBar.translucent=NO;
    [imagePickerController.navigationBar setTintColor:wlBlackColor];
    [self presentViewController:imagePickerController animated:YES completion:nil];
}

- (void)chooseMovieAction
{
//    /Users/muzhuang/Library/Developer/CoreSimulator/Devices/CEEA1018-37CD-4884-8D55-59FBCC8A0007/data/Containers/Data/Application/9F1222A1-2529-416E-99C9-FC0C0BC1F387/Library/Caches/uploads
    NSFileManager *fileManager = [NSFileManager defaultManager];
    NSArray *childerFiles=[fileManager subpathsAtPath:[WLCommonTool getUploadFilePath]];
    WLLog(@"subFile:%@",childerFiles);
    UIImagePickerController *imagePickerController = [[UIImagePickerController alloc] init];
    imagePickerController.delegate = self;
    imagePickerController.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
    imagePickerController.mediaTypes = @[(__bridge NSString *)kUTTypeMovie];
    imagePickerController.navigationBar.translucent=NO;
    [imagePickerController.navigationBar setTintColor:wlBlackColor];
    [self presentViewController:imagePickerController animated:YES completion:nil];
}

- (void)chooseAudioAction
{
    UIImagePickerController *imagePickerController = [[UIImagePickerController alloc] init];
    imagePickerController.delegate = self;
    imagePickerController.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
    imagePickerController.mediaTypes = @[(__bridge NSString *)kUTTypeAudio];
    imagePickerController.navigationBar.translucent=NO;
    [imagePickerController.navigationBar setTintColor:wlBlackColor];
    [self presentViewController:imagePickerController animated:YES completion:nil];
}
/*
#pragma mark - UIImagePickerDelegate
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary<NSString *,id> *)info
{
    NSString  *mediaType = [info objectForKey:UIImagePickerControllerMediaType];
    if (_index==0&&[mediaType isEqualToString:(__bridge NSString *)kUTTypeImage])
    {
        UIImage *selectImage = [info objectForKey:UIImagePickerControllerOriginalImage];
        NSString *type = @"jpg";
        NSData *data = UIImageJPEGRepresentation(selectImage, 0.5);
        NSData *smallData = UIImageJPEGRepresentation(selectImage, 0.1);
        if (data==nil) {
            data = UIImagePNGRepresentation(selectImage);
            type = @"png";
        }
//        data write
        NSDateFormatter *dateformat=[[NSDateFormatter  alloc]init];
        [dateformat setDateFormat:@"yyMMddHHmmss"];
        NSString *strTime = [dateformat stringFromDate:[NSDate date]];
        NSString *fileName = [NSString stringWithFormat:@"%@.%@",strTime,type];
        NSString *bigFilePath = [NSString stringWithFormat:@"%@/BigPhotos/%@", [WLFileHandle documentsDir], fileName];
        NSString *smallFilePath = [NSString stringWithFormat:@"%@/SmallPhotos/%@", [WLFileHandle documentsDir], fileName];
        [WLFileHandle createFileAtPath:bigFilePath
                                                 overwrite:YES
                                                     error:nil];
        [WLFileHandle createFileAtPath:smallFilePath
                                                 overwrite:YES
                                                     error:nil];
        [data writeToFile:bigFilePath atomically:NO];
        [data writeToFile:smallFilePath atomically:NO];
        NSString *mediaURL = [info objectForKey:UIImagePickerControllerReferenceURL];
        [self addTaskToCenterWihtFileURL:nil fileData:data fileName:fileName fileType:SPFileTypePhoto mediaURL:mediaURL];
    }
    else if (_index==1&&[mediaType isEqualToString:(__bridge NSString *)kUTTypeMovie])
    {
        
        NSURL *sourceURL = [info objectForKey:UIImagePickerControllerMediaURL];
        //        NSLog(@"%@",[NSString stringWithFormat:@"%f s", [self getVideoLength:sourceURL]]);
        //        NSLog(@"%@", [NSString stringWithFormat:@"%.2f kb", [self getFileSize:[sourceURL path]]]);
        NSURL *newVideoUrl ; //一般.mp4
        NSDateFormatter *formater = [[NSDateFormatter alloc] init];//用时间给文件全名，以免重复，在测试的时候其实可以判断文件是否存在若存在，则删除，重新生成文件即可
        [formater setDateFormat:@"yyyyMMddHHmmss"];
        NSString *documentPath = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES).firstObject;
        newVideoUrl = [NSURL fileURLWithPath:[documentPath stringByAppendingFormat:@"/%@.mp4", [formater stringFromDate:[NSDate date]]]] ;//这个是保存在app自己的沙盒路径里，后面可以选择是否在上传后删除掉。我建议删除掉，免得占空间。
        
        //        newVideoUrl = [NSURL fileURLWithPath:[NSHomeDirectory() stringByAppendingString:@"/Documents/output1.mp4"]];
        NSString *mediaURL = [info objectForKey:UIImagePickerControllerReferenceURL];
        [SVProgressHUD showAndAutoCloseWithStatus:@"正在加入队列……" delayTime:3.f];
        WLWkSelf
        [WLFileHandle convertVideoQuailtyWithInputURL:sourceURL outputURL:newVideoUrl completeHandler:^(AVAssetExportSession *handler) {
            if (handler.status == AVAssetExportSessionStatusCompleted) {
                [SVProgressHUD showAndAutoCloseWithStatus:@"加入队列成功" delayTime:3.f];
                [weakSelf addTaskToCenterWihtFileURL:newVideoUrl fileData:nil fileName:nil fileType:SPFileTypeVideo mediaURL:mediaURL];
                [weakSelf judgeHaveTask];
            }
        }];
    }
    
    [picker dismissViewControllerAnimated:YES completion:nil];
}*/
- (void)configHaveTaskState {
    if (_redPointView == nil) {
        _redPointView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"WL_have_new_task"]];
        _redPointView.frame = CGRectMake(44 - _redPointView.frame.size.width, 10, _redPointView.frame.size.width, _redPointView.frame.size.height);
    }
    if (!_redPointView.superview) {
        [self.navigationItem.rightBarButtonItem.customView addSubview:_redPointView];
    }
}
- (void)judgeHaveTask {
    
    BOOL hasUpLoadTasks = [[WLUpLoadCenter shareInstance] getTasksArray].count > 0 ? YES : NO;
    BOOL hasDownLoadTasks = [[WLDownLoadCenter shareInstance] getTasksArray].count > 0 ? YES : NO;
    if (!hasUpLoadTasks && !hasDownLoadTasks) {
        [self configCompleteAllTasksState];
    } else {
        [self configHaveTaskState];
    }
}

- (void)configCompleteAllTasksState {
    if (_redPointView.superview) {
        [_redPointView removeFromSuperview];
    }
}
/*
- (void)addTaskToCenterWihtFileURL:(NSURL *)fileUrl fileData:(NSData *)fileData fileName:(NSString *)fileName fileType:(SPFileType)fileType mediaURL:(NSString *)mediaURL{
    
    WLFileUpDownLoadModel *model = [[WLFileUpDownLoadModel alloc] init];
    model.filePath = fileUrl.path;
    model.fileURL = fileUrl;
    model.fileType = fileType;
    model.loadState = FileLoadingStateWaiting;
    model.fileData = fileData;
    if (fileName == nil) {
        model.fileName = fileUrl.path.lastPathComponent;
    } else {
        model.fileName = fileName;
    }
    model.isUpLoad = YES;
    NSArray *tasksArr = @[model];
    [[WLUpLoadCenter shareInstance] addTasks:tasksArr];
}
*/
- (void)addTaskWithListArr:(NSArray <HXPhotoModel *> *)listArr fileType:(SPFileType)fileType{
    NSMutableArray *reslutList = [NSMutableArray new];
    for (HXPhotoModel *model in listArr) {
        WLFileUpDownLoadModel *fileModel = [self createFileUpDownLoadModelWithPhotoModel:model fileType:fileType];
        [reslutList addObject:fileModel];
    }
    [[WLUpLoadCenter shareInstance] addTasks:reslutList];
    [self judgeHaveTask];
}
- (WLFileUpDownLoadModel *)createFileUpDownLoadModelWithPhotoModel:(HXPhotoModel *)photoModel fileType:(SPFileType)fileType  {
    WLFileUpDownLoadModel *model = [[WLFileUpDownLoadModel alloc] init];
//    model.filePath = photoModel.fileURL.path;
//    model.fileURL = photoModel.fileURL;
    model.fileType = fileType;
    model.loadState = FileLoadingStateWaiting;
    model.localIdentifier = photoModel.asset.localIdentifier;
    NSString *fileName = [photoModel.asset valueForKey:@"filename"];
    if (photoModel.asset.mediaType == PHAssetMediaTypeVideo) {
        fileName = [fileName stringByReplacingOccurrencesOfString:@"IMG" withString:@"video"];
        fileName = [fileName stringByReplacingOccurrencesOfString:@"img" withString:@"video"];
    }
    model.fileName = fileName;
    model.fileTotalBytes = photoModel.orginalBytes;
    model.fileURL = photoModel.fileURL;
    model.mediaLocalURL = [self getLiberayURLWithModel:photoModel];
    model.isUpLoad = YES;
    return model;
}
- (NSURL *)getLiberayURLWithModel:(HXPhotoModel *)photoModel {
    PHAsset *asset = photoModel.asset;
    NSString *localID = asset.localIdentifier;
    NSURL *url = photoModel.fileURL;
    NSArray *temp = [localID componentsSeparatedByString:@"/"];
    NSString *uploadVideoFilePath = nil;
    if (temp.count > 0) {
        NSString *assetID = temp[0];
        NSString *ext = url.pathExtension;
        if (assetID && ext) {
            uploadVideoFilePath = [NSString stringWithFormat:@"assets-library://asset/asset.%@?id=%@&ext=%@", ext, assetID, ext];
        }
    }
    return [NSURL URLWithString:uploadVideoFilePath];
}
- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker
{
    [picker dismissViewControllerAnimated:YES completion:nil];
}

- (void)uploadPhotoName:(NSString *)filename photoSize:(float)photoSize path:(NSString *)strPath
{
    WLWkSelf
    NSDictionary *params = @{@"fileName":filename,@"fileSize":@(floor(photoSize*100) / 100),@"fileType":@1,@"filePath":strPath};
    [WLHttpManager WLRequestMethod:RequestTypePost urlStr:@"storage/add/item" withParamsDic:params success:^(NSDictionary *successDict) {
        [weakSelf.photoVC.collectionView.mj_header beginRefreshing];
    } failure:^(NSString *errorMsg, NSInteger errorTag) {
        [weakSelf showHUDMessage:errorMsg];
    } error:^(NSError *error) {
        
    } inView:self.view];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
